(function (vc, vm) {
    vc.extends({
        data: {
            editShopReturnAddressInfo: {
                addressId: '',
                name: '',
                link: '',
                address: '',
                seq: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editShopReturnAddress', 'openEditShopReturnAddressModal', function (_params) {
                $that.refreshEditShopReturnAddressInfo();
                $('#editShopReturnAddressModel').modal('show');
                vc.copyObject(_params, $that.editShopReturnAddressInfo);
                $that.editShopReturnAddressInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editShopReturnAddressValidate: function () {
                return vc.validate.validate({
                    editShopReturnAddressInfo: $that.editShopReturnAddressInfo
                }, {
                    'editShopReturnAddressInfo.name': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "收货人名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "收货人名称太长"
                        },
                    ],
                    'editShopReturnAddressInfo.link': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "联系电话不能为空"
                        },
                        {
                            limit: "phone",
                            param: "",
                            errInfo: "联系电话格式错误"
                        },
                    ],
                    'editShopReturnAddressInfo.address': [
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "详细地址太长"
                        },
                    ],
                    'editShopReturnAddressInfo.seq': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "排序不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "排序不是有效数字"
                        },
                    ],
                    'editShopReturnAddressInfo.addressId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "地址ID不能为空"
                        }
                    ]
                });
            },
            editShopReturnAddress: function () {
                if (!$that.editShopReturnAddressValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/shopReturnAddress/updateShopReturnAddress',
                    JSON.stringify($that.editShopReturnAddressInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editShopReturnAddressModel').modal('hide');
                            vc.emit('shopReturnAddressManage', 'listShopReturnAddress', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditShopReturnAddressInfo: function () {
                $that.editShopReturnAddressInfo = {
                    addressId: '',
                    name: '',
                    link: '',
                    address: '',
                    seq: ''
                }
            }
        }
    });
})(window.vc, window.vc.component);
